﻿using System;
using System.Collections.Generic;
using System.Text;
using BaseData;

namespace ShiziEntity.User
{
    /// <summary>
    /// 用户基类实体
    /// </summary>
    [Serializable]
	public class UserBase
	{
		public UserBase()
		{
		}
		
		private int id;
		private string userName;
		private string cityName;
		private string password;
		private int userType;
		private string realName;
        private string email;
        private DateTime? registDate;
        private int? isValid;
		private string referrer;
		
		/// <summary>
		/// 用户编号
		/// </summary>
		public int UserID
		{
			set {id=value;}
			get {return id;}
		}
		/// <summary>
		/// 用户名
		/// </summary>
		public string UserName
		{
			set {userName=value;}
			get {return userName;}
		}
		/// <summary>
		/// 城市名称
		/// </summary>
		public string CityName
		{
			set {cityName=value;}
			get {return cityName;}
		}
		/// <summary>
		/// 用户密码
		/// </summary>
		public string Password
		{
			set {password=value;}
			get {return password;}
		}
		/// <summary>
		/// 用户类别（权限）
		/// </summary>
		public int UserType
		{
			set {userType=value;}
			get {return userType;}
		}
		/// <summary>
		/// 真实姓名
		/// </summary>
		public string RealName
		{
			set {realName=value;}
			get {return realName;}
		}
		/// <summary>
		/// 邮箱
		/// </summary>
		public string Email
		{
			set {email=value;}
			get {return email;}
		}
		/// <summary>
		/// 注册时间
		/// </summary>
		public DateTime? RegistDate
		{
			set {registDate=value;}
			get {return registDate;}
		}
		/// <summary>
		/// 是否有效:0--无效,1--有效
		/// </summary>
		public int? IsValid
		{
			set {isValid=value;}
			get {return isValid;}
		}
		/// <summary>
		/// 推荐人
		/// </summary>
		public string Referrer
		{
			set {referrer=value;}
			get {return referrer;}
		}

        /// <summary>
        /// 获取用户类别
        /// </summary>
        /// <returns>用户类别</returns>
        public virtual UserType GetUserType()
        {
            return (UserType)Enum.Parse(typeof(UserType), this.UserType.ToString(), true);
        }

        /// <summary>
        /// 获取保存用户基类信息的SQL
        /// </summary>
        /// <returns>SQL语句</returns>
        public virtual string GetInsertSql()
        {
            StringBuilder sql = new StringBuilder();
            StringBuilder strFiled = new StringBuilder();
            StringBuilder strValue = new StringBuilder();
            if (this.UserName != null)
            {
                strFiled.Append("UserName,");
                strValue.Append("'" + this.UserName + "',");
            }
            if (this.CityName != null)
            {
                strFiled.Append("CityName,");
                strValue.Append("'" + this.CityName + "',");
            }
            if (this.Password != null)
            {
                strFiled.Append("Password,");
                strValue.Append("'" + this.Password + "',");
            }
            if (this.UserType > -1)
            {
                strFiled.Append("UserType,");
                strValue.Append("" + this.UserType + ",");
            }
            if (this.RealName != null)
            {
                strFiled.Append("RealName,");
                strValue.Append("'" + this.RealName + "',");
            }
            if (this.Email != null)
            {
                strFiled.Append("Email,");
                strValue.Append("'" + this.Email + "',");
            }
            if (this.RegistDate != null)
            {
                strFiled.Append("RegistDate,");
                strValue.Append("'" + this.RegistDate + "',");
            }
            if (this.IsValid != null)
            {
                strFiled.Append("IsValid,");
                strValue.Append("" + this.IsValid + ",");
            }
            if (this.Referrer != null)
            {
                strFiled.Append("Referrer,");
                strValue.Append("'" + this.Referrer + "',");
            }
            sql.Append("insert into UserBase(");
            sql.Append(strFiled.ToString().Remove(strFiled.Length - 1));
            sql.Append(")");
            sql.Append(" values (");
            sql.Append(strValue.ToString().Remove(strValue.Length - 1));
            sql.Append(")");
            sql.Append(";select @@IDENTITY");
            return sql.ToString();
        }
	}
}